package sample.plugin.di;

import com.qiplat.open.ui.widget.dialog.QiBottomDialog;
import com.rapid.api.Unit;
import com.rapid.api.ext.framework.BaseObject;
import com.rapid.api.framework.domain.page.DomainPageService;
import com.rapid.api.framework.domain.window.WindowService;
import com.rapid.api.framework.project.primary.ProjectLifecycleEvent;
import com.rapid.api.project.Project;
import com.rapid.api.project.ProjectManager;
import com.rapid.api.project.service.LanguageManager;
import com.rapid.framework.extension.annotation.Import;

/**
 * 这是个随意写的类
 * 该类演示同时使用字段注入和构造注入
 */
public class MixedInject extends BaseObject implements ProjectLifecycleEvent {
    //不指定unit默认使用全局作用域
    @Import
    private WindowService windowService;
    //从项目单元装配该对象，标识符为std.android，即装载标准安卓工程的LanguageProvider
    @Import(unitId = Unit.Ids.PROJECT, identifier = "std.android")
    private LanguageManager languageManager;

    //从构造方法注入
    private DomainPageService pageService;

    public MixedInject(DomainPageService pageService) {
        this.pageService = pageService;
    }

    @Override
    public void beforeLoadingProject(Project project, ProjectManager<?> projectManager) {

    }

    @Override
    public void afterLoadingProject(Project project, ProjectManager<?> projectManager) {
        runUI(() -> {
            String message = "成功装配：\n";
            message += windowService + "\n\n";
            message += pageService + "\n\n";
            message += languageManager;
            QiBottomDialog.show(
                    getActivity(),
                    getClass().getSimpleName(),
                    message
            );
        });
    }

    @Override
    public void onCloseProject(Project project, ProjectManager<?> projectManager) {

    }
}
